package net.semanticmetadata.lire.utils;

import net.semanticmetadata.lire.HDLireOper;
import org.apache.lucene.index.IndexWriter;

import java.io.File;
import java.io.IOException;

/**
 * Created by qingshengzheng on 17/5/16.
 */
public class InitIndexOfImage {

    private static  HDLireOper hdLireOper;

    /**
     * 文件初始化
     * @param path
     */
    public static  void getFiles(String path) {
        if(hdLireOper==null)
            hdLireOper=new HDLireOper();
        hdLireOper.initIndexWrite();
        File file = new File(path);
        if (file.exists()) {
            File[] files = file.listFiles();
            if (files.length == 0) {
                return;
            } else {
                for (File file2 : files) {
                    if (file2.isDirectory()) {
                        getFiles(file2.getAbsolutePath());
                    } else {
                        hdLireOper.addImageDoc(file2.getAbsolutePath());
                        //hdLireOper.commitWrite();

                    }
                }
            }
        } else {
        }
        try {
            hdLireOper.commitWrite();
           hdLireOper.closeWrite();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     *
     * @param args
     */
    public static void main(String [] args)
    {
        String path="/work/scrapy/data/fruitimgs/1";
        getFiles(path);
    }

}
